<template>
	<view class="footer">
		<view class="footer-title">
			当前用户信息：
		</view>
		<view>{{ user.userName }} {{ user.idCard }}</view>
		<view @click="loginOut" style="color: blue;">【退出】</view>
	</view>
</template>
<script>
	import {
		logOut
	} from '@/api/home/index';
	import {
		desensitizeChineseName,
		validateAndDesensitizeIDCard
	} from 'utils/custom.js';
	export default {
		name: 'Message',
		created() {
			this.getInit();
		},
		data() {
			return {
				tokenId: '',
				user: {},
			}
		},

		methods: {
			getInit() {
				let result = uni.getStorageSync('user');
				this.tokenId = uni.getStorageSync('tokenId');
				console.log('result', result);
				if (result && result.userName.includes('*')) {
					this.user = result;
				} else {
					const name = desensitizeChineseName(result.userName);
					const {
						isValid,
						desensitizedIDCard
					} = validateAndDesensitizeIDCard(result.idCard);
					this.user = {
						...result,
						userName: name,
						idCard: desensitizedIDCard,
					};
				}
			},
			loginOut() {
				uni.showLoading({
					title: '退出中...'
				})
				logOut(this.tokenId).then(() => {
					uni.removeStorageSync('user');
					uni.removeStorageSync('token');
					uni.removeStorageSync('tokenId');
					uni.hideLoading();
					uni.showToast({
						title: '退出成功'
					})
					uni.$u.route({
						url: 'pages/home/index'
					})
				})
			}
		}
	}
</script>
<style lang="less" scoped>
	.footer {
		position: fixed;
		left: 40px;
		bottom: 20px;
		display: flex;
		width: 90%;
		font-size: 22px;
		font-weight: 600;

		.footer-title {
			color: #4B81FF;
		}
	}
</style>